<?php
namespace app\daifast\controller; 
use \think\Db; 


class Link extends \think\Controller
{
     
    public function index(){
        $data = Db('baode_links')->order("id desc")->paginate(10); 
        $listArr = $data->items();
        $pages = $data->render();
        return $this->allFetch(get_defined_vars());
    }
    
    
    public function add(){
        //获取广告位信息
        $lid = intval(input('lid'));
        $lid and $linkInfo = Db('baode_links')->where(['id'=>intval($lid)])->find();
        
        //编辑或添加
        if(input('sbt')){
            $data['url'] = input('url');
            $data['logo'] = input('path');
            input('status') and $data['status'] = input('status');
            $data['on_time'] = time();
            //写库
            $lid and Db('baode_links')->where(['id'=>intval($lid)])->update($data);
            $lid or Db('baode_links')->insert($data);
            $this->showMsg('操作成功', url('Link/index'));
        }
    
        return $this->allFetch(get_defined_vars());
    }
    
    
    //删除
    public function delete(){
        $lid = intval(input('lid'));
        Db('baode_links')->where(['id'=>$lid])->delete();
        $this->showMsg('删除成功', url('Link/index'));
        
    }
    
    //友情链接禁止或开启
    public function setstatus(){
        Db::table('baode_links')->where('id', input('link_id'))->update(['status' => input('status')]);
        echojson("ok", 1, input('status'));
    }
   
}
